home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Interactive Reference Guide / C-C++ Interactive Reference Guide.iso / c_ref / csource1 / xlib20 / example2.c < prev    next >
C/C++ Source or Header  |  1993-09-21  |  1KB  |  50 lines

  1. #include <stdio.h>
  2. #include <xlib.h>
  3. #define som _emit 0x66               /* switch operand mode */
  4. #define sam _emit 0x67               /* switch address mode */
  5. long __far getextmem(long address);
  6.  
  7. int goterr = 0;                      /* error flag */
  8.  
  9. main()
  10. {
  11.   long l;
  12.   l = INITXLIB();                    /* initialize XLIB */
  13.   if(l != 0)
  14.   {
  15.     printf("Library initialization error:  %lX",l);
  16.     return 0;
  17.   }
  18.   l = getextmem(0x100000);           /* read first address in 2ond meg */
  19.   if(goterr != 0)
  20.   {
  21.     printf("Inline mode-switch error:  %lX",l);
  22.     return 0;
  23.   }
  24.   printf("%lX\n",l);
  25. }
  26.  
  27. long __far getextmem(long address)
  28. {
  29.   __asm
  30.   {
  31.     som                             ;mov  eax,[bp+6]
  32.     mov       ax,[bp+6]             ;  ""
  33.     call      INLINEPM
  34.     jc        error                 ;Error code in ax
  35.     mov       ds,es:FLATDSEL
  36.     sam                             ;push dword ptr [eax]
  37.     som                             ;  ""
  38.     _emit     0ffh                  ;  ""
  39.     _emit     030h                  ;  ""
  40.     pop       ax
  41.     pop       dx
  42.     call      es:INLINERMPTR
  43.     jmp       done
  44. error:
  45.     xor       dx,dx                 ;Return error code in dx:ax
  46.     inc       goterr
  47. done:
  48.   }
  49. }
  50.